//
//  PersonalSettingViewController.m
//  easystudy
//
//  Created by 七 on 16/8/30.
//  Copyright © 2016年 kane. All rights reserved.
//

#import "PersonalSettingViewController.h"
#import "ModifyPasswordController.h"
@interface PersonalSettingViewController ()

@end

@implementation PersonalSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (![UserEntity sharedUser].loginSuccess) {
        _quitBtn.hidden = YES;
        _groupSetTableView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64);
    }
    [_groupSetTableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)backBtn:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

//退出
- (IBAction)quit:(id)sender {
    [UserEntity sharedUser].loginSuccess = NO;
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark UITableViewDelegate & datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identify = [NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
        [cell setAccessoryType:indexPath.section == 1?UITableViewCellAccessoryNone:UITableViewCellAccessoryDisclosureIndicator];
    }
    if (indexPath.row == 0) {
        if ([UserEntity sharedUser].loginSuccess) {//登录成功
            cell.textLabel.text = @"修改密码";
        }else{
           cell.textLabel.text = @"注册登录";
        }
    }else{
        cell.textLabel.text = @"分享设置";
    }
    
    return cell;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        if ([UserEntity sharedUser].loginSuccess) {//登录成功
            ModifyPasswordController *modifyVC = [[ModifyPasswordController alloc] init];
            [self.navigationController pushViewController:modifyVC animated:YES];
        }else{
//            AccountLoginController *loginVC = [[AccountLoginController alloc] init];
//            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginVC];
//            [self.navigationController presentViewController:nav animated:YES completion:nil];
        }
    }else{
        
    }
    
}

@end
